package com.pitaya.avatar.action;

import java.util.ArrayList;
import java.util.List;
import java.util.Map;

import com.opensymphony.xwork2.ActionContext;
import com.opensymphony.xwork2.ActionSupport;
import com.pitaya.avatar.domain.House;
import com.pitaya.avatar.service.IHouseService;

public class HouseAction extends ActionSupport{

	private static final long serialVersionUID = 1L;
	private IHouseService houseService;
	private House house;
	private List<House> houseList;

	public List<House> getSchoolList() {
		return houseList;
	}

	public void setSchoolList(List<House> houseList) {
		this.houseList = houseList;
	}

	public House getHouse() {
		return house;
	}

	public void setHouse(House house) {
		this.house = house;
	}

	public void setHouseService(IHouseService houseService) {
		this.houseService = houseService;
	}
	
	public String findHouse() {
		if(house == null) {
			house = new House();
		}
		
		if(house.getName().equals("")) {
			return "findFail";
		}
		Map<String,Object> session = ActionContext.getContext().getSession();
		List<House> list = new ArrayList<House>();
			

		//need add code
		
		list = houseService.find(house);
		for (int i = 0; i < list.size(); i++) {
			House sch = list.get(i);
			System.out.println(sch.getHid());
			System.out.println(sch.getName());
			System.out.println(sch.getLongitude());
			System.out.println(sch.getLatitude());
		}
		
		session.put("houseList", list);
		return "findSuccess";
	}
	
	public String addHouse() {
		Map<String,Object> session = ActionContext.getContext().getSession();
		house = (House)session.get("addHouse");
		if(houseService.add(house)) {
			return "addSuccess"; 
		}else {
			return "addFailed";
		}
	}
}
